package com.google.gson;

import com.google.gson.a.a;
import com.google.gson.b.d;
import com.google.gson.internal.bind.TypeAdapter;
import com.google.gson.internal.bind.TypeAdapter.Factory;
import com.google.gson.internal.bind.l;
import com.google.gson.internal.i;
import com.google.gson.internal.k;
import java.io.IOException;
import java.lang.reflect.Type;

final class g implements Factory {
    private final i a;
    private final i b;
    private final JsonDeserializationContext c;
    private final JsonSerializationContext d;

    public g(final f fVar, i iVar, i iVar2) {
        this.a = iVar;
        this.b = iVar2;
        this.c = new JsonDeserializationContext(this) {
            final /* synthetic */ g b;

            public Object deserialize(j jVar, Type type) throws n {
                return fVar.a(jVar, type);
            }
        };
        this.d = new JsonSerializationContext(this) {
            final /* synthetic */ g b;

            public j serialize(Object obj) {
                return fVar.a(obj);
            }

            public j serialize(Object obj, Type type) {
                return fVar.a(obj, type);
            }
        };
    }

    public TypeAdapter create(l lVar, a aVar) {
        final Type b = aVar.b();
        final JsonSerializer jsonSerializer = (JsonSerializer) this.a.a(b, false);
        final JsonDeserializer jsonDeserializer = (JsonDeserializer) this.b.a(b, false);
        if (jsonSerializer == null && jsonDeserializer == null) {
            return null;
        }
        final l lVar2 = lVar;
        final a aVar2 = aVar;
        return new TypeAdapter(this) {
            final /* synthetic */ g f;
            private TypeAdapter g;

            private TypeAdapter a() {
                TypeAdapter typeAdapter = this.g;
                if (typeAdapter != null) {
                    return typeAdapter;
                }
                typeAdapter = lVar2.a(this.f, aVar2);
                this.g = typeAdapter;
                return typeAdapter;
            }

            public void a(d dVar, Object obj) throws IOException {
                if (jsonSerializer == null) {
                    a().a(dVar, obj);
                } else if (obj == null) {
                    dVar.f();
                } else {
                    k.a(jsonSerializer.serialize(obj, b, this.f.d), dVar);
                }
            }

            public Object b(com.google.gson.b.a aVar) throws IOException {
                if (jsonDeserializer == null) {
                    return a().b(aVar);
                }
                j a = k.a(aVar);
                return a.j() ? null : jsonDeserializer.deserialize(a, b, this.f.c);
            }
        };
    }
}
